const { DataTypes } = require('sequelize');
const { sequelize } = require('../utils/database');

const Feed = sequelize.define('Feed', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '用户ID'
  },
  activity_id: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '关联活动ID'
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '动态内容'
  },
  media_urls: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '媒体文件URLs'
  },
  feed_type: {
    type: DataTypes.ENUM('activity', 'participation', 'achievement', 'post'),
    allowNull: false,
    defaultValue: 'post',
    comment: '动态类型'
  },
  likes_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '点赞数量'
  },
  comments_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '评论数量'
  },
  is_public: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    comment: '是否公开'
  }
}, {
  tableName: 'activity_feeds',
  timestamps: true,
  indexes: [
    {
      fields: ['user_id']
    },
    {
      fields: ['activity_id']
    },
    {
      fields: ['feed_type']
    },
    {
      fields: ['createdAt']
    },
    {
      fields: ['is_public']
    }
  ]
});

module.exports = Feed; 